<?php

    class Site extends Controller{
        //constructor
        function __construct(){
            parent::Controller();
	    $this->is_logged_in();
        }
		
        //member area...
        function member(){
			//$data=$this->statistics_model->setdata();
			$data["title"] = "Member Area.";	//set title.
			$data["topic"] = "Welcome.";
			$data["navigator"] = "&nbsp;&#8250;&nbsp;Member Profile Node";
	
			//view
			$this->load->view('inc/site/main_content',$data);
        }
		
        //is loged ?
        function is_logged_in(){
            $is_logged_in = $this->session->userdata('is_logged_in');
			if(!isset($is_logged_in) || $is_logged_in != true)
			{
					$data["title"] = "Permission Deny.";
					$data["topic"] = "You don have permission to access this page.";
					$data["content"]='msg/permission_deny';
			
					//view
					$this->load->view('inc/one_cols',$data);	//load view one cols.	
			}		
        }
		
		function upload_display() {
			if(isset($_POST['upload'])) {
						  
			  //$path = base_url().'km_resource/member_display';
			  $config['upload_path'] = './km_resource/member_display/';
			  $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
			  $config['max_size']  = '0';
			  $config['max_width']  = '0';
			  $config['max_height']  = '0';
			  /* Load the upload library */
			  $this->load->library('upload', $config);
		
			  /* Create the config for image library */
			  /* (pretty self-explanatory) */
			  $configThumb = array();
			  $configThumb['image_library'] = 'gd2';
			  $configThumb['source_image'] = '';
			  $configThumb['create_thumb'] = TRUE;
			  $configThumb['maintain_ratio'] = TRUE;
			  
			  $configThumb['width'] = 135;
			  $configThumb['height'] = 145;
			  
			  /* Load the image library */
			  $this->load->library('image_lib');
		
			  for($i = 1; $i < 2; $i++) {
				$upload = $this->upload->do_upload('image'.$i);
				if($upload === FALSE) continue;
				$data = $this->upload->data();
				$uploadedFiles[$i] = $data;
				
				if($data['is_image'] == 1) {
				  $configThumb['source_image'] = $data['full_path'];
				  $this->image_lib->initialize($configThumb);
				  $this->image_lib->resize(); 
				}
			  }
			 	/*echo "<ul>";
					foreach($this->upload->data() as $item => $value){
						echo "<li>";
						echo $item;
						echo $value;
						echo "</li>";
					}
				echo "</ul>";*/
				
				//send to model.
				$data['file_name'];
				$data['file_ext'];
				$data['raw_name'];
				$this->load->model('member/member_model');
				$member_display = $this->member_model->upload_display($data); 
				
				if($member_display){
					$path = base_url()."site/member";
					redirect($path);
				}
			}					
		}
		
		function edit_password(){
			$password1 = $this->input->post('new_password');
			$password2 = $this->input->post('confirm_new_password');
			if($password1 != $password2){
				echo "No Match!!";
			}
			else
			{
				$data['new_password'] = $this->input->post('new_password');
				$data['id'] = $this->session->userdata('member_id');
				$this->load->model('member/member_model');
				
				$query = $this->member_model->edit_password($data);
				
				if($query){
					echo "edit password ok";
				}
				else
				{
					echo "edit password fail";
				}
			}
		}
		
		function edit_userprofile(){
			$this->load->model('member/member_model');
			$query = $this->member_model->edit_userprofile();
			
			if($query){
				echo "ok";
			}
			else
			{
				echo "false";
			}
		}
    }